import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class WeightCalculatorFrame extends JFrame implements ActionListener  {

		public static final int width=300;
		public static final int height=300;
		public static final double poundsPerKilo=.45359237;
		
		private JTextArea legend;
		private JLabel kiloLabel;
		private JLabel poundLabel;
		private JTextField kiloInput;
		private JTextField poundInput;
		
		
		private JButton convertToPounds;
		private JButton convertToKilos;
		
	
		
		private static final FlowLayout LAYOUT_STYLE= new FlowLayout();
		
	/**
	 * @param args
	 */
		public WeightCalculatorFrame(){
			super();
			super.setSize(WIDTH, HEIGHT);
			super.setTitle("Weight Calculator");
			
			super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
			this.setup();

		}
		public void setup(){
			kiloLabel = new JLabel("Kilograms");
			poundLabel=new JLabel("Pounds");
			
			this.legend=new JTextArea("This programs converts pounds to kilograms.", 2, 15);
			
			this.kiloInput = new JTextField(15);
			this.kiloInput.addActionListener(this);
			
			this.poundInput = new JTextField(15);
			this.poundInput.addActionListener(this);
			
			this.convertToPounds = new JButton("Convert to Pounds");
			this.convertToPounds.addActionListener(this);

			this.convertToKilos = new JButton("Convert To Kilograms");
			this.convertToKilos.addActionListener(this);
		
			Container container = this.getContentPane();
			
			container.setLayout(LAYOUT_STYLE);
			container.add(legend);
			container.add(poundLabel);
			container.add(poundInput);
			container.add(convertToKilos);
			container.add(kiloLabel);
			container.add(kiloInput);			
			container.add(convertToPounds);

		
			
			
		}
		@Override
		public void actionPerformed(ActionEvent event) {
			// TODO Auto-generated method stub
			
			if(event.getActionCommand().equals("Convert To Kilograms")){
				System.out.println("kilo");
				String poundText = poundInput.getText();
				double pounds=Double.parseDouble(poundText);
				double kilo=pounds*poundsPerKilo;
				String answer=String.valueOf(kilo);
				this.kiloInput.setText(answer);
				}
			if(event.getActionCommand().equals("Convert to Pounds")){
				System.out.println("pounds");
				String kiloText=kiloInput.getText();
				double kilos=Double.parseDouble(kiloText);
				double pounds=kilos*(1/poundsPerKilo);
				String poundOutput=String.valueOf(pounds);
				this.poundInput.setText(poundOutput);
			}
			
	


			

			
		}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		//JFrame aFrame = new JFrame();
		//aFrame.setVisible(true);
		
		WeightCalculatorFrame theCalculator = new WeightCalculatorFrame();
		theCalculator.setVisible(true);


	}


}
